package day_2022_7_to_8.day48;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/07/28 17:56
 **/
public class Day13_2_Num784_LetterCasePermutation {
    class Solution {
        List<String> result = new ArrayList<>();
        public List<String> letterCasePermutation(String s) {
            if(s.length() == 0) return result;
            char[] data = s.toCharArray();
            dfs(data, 0);
            return result;
        }
        // 回溯
        private void dfs(char[] data, int index){
            result.add(new String(data));
            for(int i = index;i < data.length;i++){
                // 如果是数字，跳过
                if(Character.isDigit(data[i])){
                    continue;
                }else if(Character.isUpperCase(data[i])){
                    // 如果是大写，转小写，然后扩展到下一个节点
                    data[i] = (char)(data[i] + 32);
                    dfs(data,i+1);
                    data[i] = (char)(data[i] - 32);
                }else {
                    // 如果是小写，转大写，然后扩展到下一个节点
                    data[i] = (char)(data[i] - 32);
                    dfs(data,i+1);
                    data[i] = (char)(data[i] + 32);
                }
            }
        }
    }
}